import { EffectAsset, game, Game, gfx, Material } from "cc";
import { Effect } from "./Common/Effect";

let lineMaterial = new Material();
lineMaterial._uuid = "line-material";
lineMaterial.initialize({
    effectName: "unlit",
    defines: { USE_VERTEX_COLOR: true },
    states: { primitive: gfx.PrimitiveMode.LINE_LIST }
});

let effectAsset = Object.assign(new EffectAsset(), Effect);
effectAsset.onLoaded();

let viewMaterial = new Material();
viewMaterial._uuid = "view-material";
viewMaterial.initialize({ effectAsset });

game.on(Game.EVENT_GAME_INITED, () => {
    lineMaterial.passes.forEach(v => v.tryCompile());
    viewMaterial.passes.forEach(v => v.tryCompile());
})

class CinestationShareAssets {
    public viewMaterial: Material = viewMaterial;
    public lineMaterial: Material = lineMaterial;

    public __setDebugProperty(k: string, v: any) {
        this.viewMaterial.setProperty(k, v);
    }
}

export const cinestationShareAssets = new CinestationShareAssets();